/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.gemom;

import java.util.*;
/**
 *
 * @author Yair Diaz
 */
public class BidTree {

    Bid root;

   public BidTree(Vector<Bid> listBids)
    {
       root = new Bid();
       for(int i=0;i<listBids.size();i++)
       insert(root,listBids.get(i),0);
    }	


//pilas con el constructor de Bid
    public void insert(Bid node, Bid theBid, int index) 
    {
      if(index<theBid.getItemflags().length){
	  		
	  	if(theBid.getItemflags()[index]==1){
			if(node.left==null)node.left=new Bid();
			
			if(index==theBid.getItemflags().length-1)
					{node.left=theBid;}
			insert(node.left,theBid,index+1);
		}
		else if(theBid.getItemflags()[index]==0){
				if(node.right==null)node.right=new Bid();
				
				if(index==theBid.getItemflags().length-1)
					{node.right=theBid;}
				insert(node.right,theBid,index+1);
		}
	  }//end outer if		
	}//end method


    public void printInOrder(Bid node)
    {
        if (node != null) 
        {
             printInOrder(node.left);
             if(node.getItemflags()!=null)System.out.println(node);
             printInOrder(node.right);
        }
     }

    public Bid getBidTreeRoot(){return root;}
}